<extend name="Public:base" />
<block name="title"><title>心e购-添加收货地址</title></block>
<block name="resources">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Wap/lib/mui/css/mui.picker.min.css"/>
</block>
<block name="body">
	<header class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">添加收货地址</h1>
	</header>
	<div class="mui-content">
		<form class="mui-input-group" method="post">
			<input type="hidden" name="id" value="{:I('get.id')}">
			<div class="mui-input-row">
				<label>您的姓名</label>
				<input type="text" name="realname" value="{$address.realname}" required placeholder="输入姓名">
			</div>
			<div class="mui-input-row">
				<label>联系电话</label>
				<input type="text" name="mob_phone" value="{$address.mob_phone}" required placeholder="输入联系电话">
			</div>
			<div class="mui-input-row" id="showCityPicker3">
				<label>所在地区</label>
				<input type="text" name="city" id="city" value="{$address.province} {$address.city} {$address.area}" required placeholder="选择所在地区" readonly>
			</div>
			<div class="mui-input-row">
				<label>详细地址</label>
				<input type="text" name="address" value="{$address.address}" required placeholder="镇、街道、门牌号">
			</div>

			<div class="mui-button-row">
				<button type="submit" class="mui-btn mui-btn-primary">确认</button>&nbsp;&nbsp;
				<if condition="$id">
					<button type="button" class="mui-btn mui-btn-danger" onclick="onDelete()">删除</button>
				</if>
			</div>
		</form>
	</div>
</block>
<block name="script">
	<script type="text/javascript" src="__PUBLIC__/Wap/lib/mui/libs/mui.picker.min.js" ></script>
	<script type="text/javascript" src="__PUBLIC__/Wap/lib/mui/libs/mui.poppicker.js" ></script>
	<script type="text/javascript" src="__PUBLIC__/Wap/lib/mui/libs/city.data-3.js" ></script>
	<script>
		function onDelete() {
			if(confirm("确认删除地址？")) {
				mui.post('/Wap/Member/add_address', {
					id: '{$id}',
					op: 'delete'
				}, function(data) {
					if(data.code === 0) {
						location.href = '/Wap/Member/address';
					} else {
						alert(data.message);
					}
				}, 'json');
			}
		}
		(function($, doc) {
			$.init();
			$.ready(function() {
				var _getParam = function(obj, param) {
					return obj[param] || '';
				};
				//-----------------------------------------
				var cityPicker3 = new $.PopPicker({
					layer: 3
				});
				cityPicker3.setData(cityData3);
				var showCityPickerButton = doc.getElementById('showCityPicker3');
				var cityResult3 = doc.getElementById('city');
				showCityPickerButton.addEventListener('tap', function(event) {
					cityPicker3.show(function(items) {
						cityResult3.value =  _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text');
						
					});
				}, false);
			})
		})(mui, document);
	</script>
</block>